package com.ljc.controller;

import com.ljc.dto.DeviceArgumentResult;
import com.ljc.dto.Result;
import com.ljc.entity.DeviceArgumentGather;
import com.ljc.service.DeviceArgumentGatherService;
import com.ljc.vo.ArgumentData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@ResponseBody
@CrossOrigin
@RequestMapping("deviceArgumentGather")
public class DeviceArgumentGatherController {

    @Autowired
    private DeviceArgumentGatherService deviceArgumentGatherService;

    @RequestMapping("getByProjectId")
    public Result getByProjectId(@RequestParam int projectId) {
        Result result = new Result();
        List<DeviceArgumentResult> argumentResult = deviceArgumentGatherService.getByProjectId(projectId);
        result.setStatus(1).setMsg("查找论证结果成功").setData(argumentResult);
        return result;
    }

    @RequestMapping("argumentConfirm")
    public Result argumentConfirm(@RequestBody ArgumentData argumentData) {
        Result result = new Result();
        try {
            deviceArgumentGatherService.argumentConfirm(argumentData);
            result.setStatus(1).setMsg("成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setStatus(0).setMsg("失败");
        }
        return result;
    }
    @RequestMapping("getByDeviceId")
    public Result getByDeviceId(@RequestParam int id){
        Result result = new Result();
        DeviceArgumentGather one = deviceArgumentGatherService.getOne(id);
        result.setStatus(1).setMsg("查询论证结论成功").setData(one);
        return result;
    }
}
